import { ElNotification, ElMessageBox } from 'element-plus'
import { useCookies } from '@vueuse/integrations/useCookies'
import NProgress from 'nprogress';

export const toast = (message, type="success") => {
    ElNotification({
        message: message,
        type: type,
        duration: 3000
    })
}

// 进度条的封装
export const nprogressLoading = () => {
    function startLoading() {
       return  NProgress.start()
    }
    function hideLoading() {
       return  NProgress.done()
    }
    return {startLoading, hideLoading}
}
// 消息提示弹出框
export const showModal=(message="提示内容",title="提示",type="warning")=>{
   return  ElMessageBox.confirm(
        message,
        title,
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: type,
        }
    )
}
//cookie的封装
export const tokenCookie=()=>{
    const Tokenkey = "admin-token"
    const cookie = useCookies()

// 获取token
    function getToken(){
        console.log(cookie.get(Tokenkey))
        return cookie.get(Tokenkey)
    }


// 设置token
    function setToken(token){
        return cookie.set(Tokenkey, token)
    }


// 清除token
    function removeToken(){
        return cookie.remove(Tokenkey)
    }
    return {getToken, setToken, removeToken}
}